package eyes;

import com.google.wave.api.*;

@SuppressWarnings("serial")
public class EyesServlet extends AbstractRobotServlet {

	@Override
	public void processEvents(RobotMessageBundle bundle) {
		Wavelet wavelet = bundle.getWavelet();
		
		if (bundle.wasSelfAdded()){
			Blip b = wavelet.appendBlip();
			TextView t = b.getDocument();
			t.append("\"THERE IS NO I IN WAVE!");
		}
		
        for (Event e : bundle.getEvents()) {
            if (e.getType() == EventType.BLIP_SUBMITTED) {
                    removeIs(e.getBlip());
            }
        }

	}
	
	private void removeIs(Blip blip)
	{
		TextView t = blip.getDocument();
		String text = t.getText();
		text = text.replace('i', 'X');
		text = text.replace('I', 'X');
		t.replace(text);
	}
	
	
}
